"""
注意：
1. 不知道导入  去setting 中间件找源码
2. 文件名应该是middleware
3. 去setting中注册
    'app_test02.middleware.auth.M1',
    'app_test02.middleware.auth.M2'
4. return response 不要忘记了
"""

from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import render,HttpResponse,redirect
# class M1(MiddlewareMixin):
#     def process_request(self,request):
#         print('M1进来')
#         return HttpResponse('无权访问!!!')
#     def process_response(self,request,response):
#         print('M1走了')
#         return  response
#
# class M2(MiddlewareMixin):
#     def process_request(self,request):
#         print('M2进来')
#     def process_response(self,request, response):
#         print('M2走了')
#         return  response

class InfoMiddleWare(MiddlewareMixin):

    def process_request(self,request):
        # 先要判断是否在 login页面
        if request.path == '/user_login':
            return

        info_dict=request.session.get('info')
        if not info_dict:
            return redirect('/user_login')
        return None